package com.dash.dashrecoder;

import com.dash.dashupload.DashMessage;
import com.dash.dashupload.DashServer;
import com.dash.pojo.Video;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class AsyTask extends Activity {

	private Button button;
	private ProgressBar progressBar;
	private TextView textView;
	private String[] srcPaths;
	// selectFileName
	private String[] absPath;;
	private String selectFileName;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		srcPaths = getIntent().getStringArrayExtra("srcPaths");
		// FileName
		selectFileName = getIntent().getStringExtra("selectFileName");
		System.out.println("Original FileName = " + selectFileName);
		for (int i = 0; i < srcPaths.length; i++) {
			System.out.println("Segment FileName = " + srcPaths[i]);
		}

		button = (Button) findViewById(R.id.button03);
		progressBar = (ProgressBar) findViewById(R.id.progressBar02);
		textView = (TextView) findViewById(R.id.textView01);

		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				new Thread() {
					public void run() {
						/*
						 * String[] srcPaths = { "/mnt/sdcard/kate/renren.mp4",
						 * "/mnt/sdcard/kate/renren1.mp4",
						 * "/mnt/sdcard/kate/renren2.mp4",
						 * "/mnt/sdcard/kate/renren3.mp4",
						 * "/mnt/sdcard/kate/renren4.mp4",
						 * "/mnt/sdcard/kate/renren5.mp4",
						 * "/mnt/sdcard/kate/renren6.mp4",
						 * "/mnt/sdcard/kate/renren7.mp4"};
						 */
						/*
						 * for (int i = 0; i < srcPaths.length; i++) {
						 * srcPaths[i]="/mnt/sdcard/MovieSegments/"+srcPaths[i];
						 * System.out.println("AsyTask:" + srcPaths[i]); }
						 */
						absPath = new String[srcPaths.length];
						for (int i = 0; i < srcPaths.length; i++) {
							// System.out.println("source file: " +
							// srcPaths[i]);
							absPath[i] = "/mnt/sdcard/MovieSegments/"
									+ srcPaths[i];
							System.out.println("absPath = " + absPath[i]);
							System.out.println("segmentFileName = "
									+ srcPaths[i]);
						}

						Video[] videos = new Video[srcPaths.length];
						for (int i = 0; i < srcPaths.length; i++) {
							videos[i] = new Video(selectFileName.substring(0,
									selectFileName.indexOf(".")), absPath[i],
									DashMessage.USERID, srcPaths.length,
									srcPaths[i].substring(0,
											srcPaths[i].indexOf(".")));
							// videos[i]=new
							// Video(selectFileName.substring(0,selectFileName.indexOf(".")),
							// srcPath, DashMessage.USERID, srcPaths.length,
							// srcPaths[i]);
						}

						DashServer.getInstance().uploadFile(videos, textView,
								progressBar);
					}
				}.start();
			}
		});
	}
}
